package com.nkym.wypan.controller;

import com.nkym.wypan.model.context.chat.CreateRoomContext;
import com.nkym.wypan.model.context.chat.RoomMemberContext;
import com.nkym.wypan.model.req.chat.CreateRoomReq;
import com.nkym.wypan.model.req.chat.JoinRoomReq;
import com.nkym.wypan.model.req.chat.PageQueryRoomReq;
import com.nkym.wypan.model.req.chat.RoomMemberReq;
import com.nkym.wypan.model.resp.socket.ChatUserInfoVO;
import com.nkym.wypan.model.resp.socket.PageQueryRoomVO;
import com.nkym.wypan.response.BaseResponse;
import com.nkym.wypan.service.RoomService;
import com.nkym.wypan.utils.UserContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName RoomController
 * @Author nkym
 * @Date 2023-11-11 17:34
 * @Version 1.0
 */
@RestController
@RequestMapping("/room")
@Api(tags = "chat room  api")
public class RoomController {


    @Resource
    RoomService roomService;


    @PostMapping("/create")
    @ApiOperation(
            value = "创建聊天室"
    )
    public BaseResponse createRoom(@Valid @RequestBody CreateRoomReq req) {
        String name = req.getName();
        Long userId = UserContextHolder.getId();
        CreateRoomContext context = new CreateRoomContext();
        context.setName(name);
        context.setUserId(userId);
        roomService.createRoom(context);
        return BaseResponse.ok();
    }

    @PostMapping("/join")
    @ApiOperation(
            value = "加入聊天室"
    )
    public BaseResponse joinRoom(@Valid @RequestBody JoinRoomReq req) {
        Long userId = UserContextHolder.getId();
        roomService.joinRoom(userId, req);
        return BaseResponse.ok();
    }


    @PostMapping("/page-list")
    @ApiOperation(value = "分页获取聊天列表")
    public BaseResponse<PageQueryRoomVO> pageGetRoom(@Valid @RequestBody PageQueryRoomReq req) {
        Long userId = UserContextHolder.getId();
        PageQueryRoomVO res = roomService.pageGetRoom(userId, req);

        return BaseResponse.ok(res);
    }
}
